package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.dto.Result;
import com.cyzy.mapper.*;
import com.cyzy.pojo.*;
import com.cyzy.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zxw
 * @create 2025-05-22 下午4:26
 */
@Service
public class CheckServiceImpl implements CheckService {
    @Autowired
    private CheckMapper checkMapper;
    @Autowired
    private SecKillMapper secKillMapper;
    @Autowired
    private ActivateCodeMapper activateCodeMapper;
    @Autowired
    private ActivityMapper activityMapper;
    @Autowired
    private AdvertMapper advertMapper;


    @Override
    public EmailTemplates getContent(String templateName) {
        return checkMapper.getContent(templateName);
    }

    //------------------------------------------
    //               秒杀课程审核
    //------------------------------------------
    @Override
    public Result selectAllSeckillInfo(GetSeckillCheck getSeckillCheck) {
        Page<CheckSeckill> page = new Page<>(getSeckillCheck.getCurrentPage(), getSeckillCheck.getPageSize());
        Page<CheckSeckill> list = checkMapper.selectAllSeckillInfo(page, getSeckillCheck);
        return Result.ok().data("list",list);
    }

    @Override
    public int updateSeckill(String seckillId, String status, String rejectReason) {
        int result = checkMapper.updateSeckill(seckillId, status, rejectReason);
        return result;
    }

    @Override
    public Seckill selectCourseId(String seckillId) {
        QueryWrapper<Seckill> yr = new QueryWrapper<>();
        yr.eq("seckill_id", seckillId);

        return secKillMapper.selectOne(yr);
    }

    @Override
    public void insertSeckill(List<ActivateCode> codeList) {
        if (codeList != null && !codeList.isEmpty()) {
            activateCodeMapper.insertBatch(codeList);
        }
    }

    @Override
    public String selectUserEmail(long seckillId) {
        return checkMapper.selectUserEmail(seckillId);
    }

    //------------------------------------------
    //               活动审核
    //------------------------------------------
    @Override
    public Result selectAllActivityInfo(GetActivityCheck getActivityCheck) {
        Page<CheckActivity> page = new Page<>(getActivityCheck.getCurrentPage(), getActivityCheck.getPageSize());
        Page<CheckActivity> list = checkMapper.selectAllActivityInfo(page, getActivityCheck);
        return Result.ok().data("list",list);
    }

    @Override
    public Activity selectActivity(String activityId) {
        QueryWrapper<Activity> yr = new QueryWrapper<>();
        yr.eq("activity_id", activityId);
        return activityMapper.selectOne(yr);
    }

    @Override
    public String selectActivityUserEmail(long activityId) {
        return checkMapper.selectActivityUserEmail(activityId);
    }

    @Override
    public int updateActivity(String activityId, String status, String rejectReason) {
        int result = checkMapper.updateActivity(activityId, status, rejectReason);
        return result;
    }


    //------------------------------------------
    //               广告审核
    //------------------------------------------
    @Override
    public Result selectAllAdvertInfo(GetAdvertCheck getAdvertCheck) {
        Page<Advert> page = new Page<>(getAdvertCheck.getCurrentPage(), getAdvertCheck.getPageSize());
        Page<Advert> list = checkMapper.selectAllAdvertInfo(page, getAdvertCheck);
        return Result.ok().data("list", list);
    }

    @Override
    public Advert selectAdvertById(String advertId) {
        QueryWrapper<Advert> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("advert_id", advertId);
        return advertMapper.selectOne(queryWrapper);
    }

    @Override
    public String selectAdvertUserEmail(long advertId) {
        return checkMapper.selectAdvertUserEmail(advertId);
    }

    @Override
    public int updateAdvert(String advertId, String status, String rejectReason) {
        return checkMapper.updateAdvert(advertId, status, rejectReason);
    }
}
